package com.ytz.mq.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.MessageProperties;

import java.nio.charset.StandardCharsets;

/**
 * 12/29  11:59
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        ConnectionFactory connectionFactory = new ConnectionFactory();
        connectionFactory.setHost("192.168.66.100");
        connectionFactory.setPort(5672);
        connectionFactory.setUsername("ytz");
        connectionFactory.setPassword("ytz");
        connectionFactory.setVirtualHost("/");
        Connection connection = connectionFactory.newConnection();
        Channel channel = connection.createChannel();

        channel.queueDeclare("work_queue", true, false, false, null);
        for (int i = 1; i <= 100; i++) {
            channel.basicPublish("", "work_queue", MessageProperties.PERSISTENT_TEXT_PLAIN,
                    ("你好，这是今天的第" + i + "条消息").getBytes(StandardCharsets.UTF_8));


        }
        channel.close();
        connection.close();
    }
}
